#ifndef SHOTSCREENSWEBAPI_H
#define SHOTSCREENSWEBAPI_H

#include <QObject>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QUrl>
#include <QNetworkRequest>
#include <QNetworkProxy>
#include <QHttp>
class ShotScreensWebAPI : public QObject
{
    Q_OBJECT
public:
    explicit ShotScreensWebAPI(QObject *parent = 0,QString login = "",QString password = "");
    void Login();
    void Logout();
    void CreateFolder(QString folder_name);
    void GetFolderList();
    void UploadImage(QString image_caption, QString folder_hash, QByteArray image_data);
#define NO 0
#define LOGIN 1
#define CREATE_FOLDER 2
#define GET_FOLDER_LIST_STATE 3
#define UPLOAD_FILE_STATE 4
#define LOGOUT_STATE 5


    enum API_STATE
    {
        NO_STATE,
        LOGIN_STATE,
        CREATE_FOLDER_STATE,
        GET_FOLDER_LIST,
        UPLOAD_FILE,
        LOGOUT
    };
    int GetCurrentAPIState();
    QList <QString> folderNames;
    QList <QString> folderHashes;
private:
    void ConnectAll();


public slots:


private slots:
    void RequestIsFinished(QNetworkReply *);

private:
    typedef struct
    {
        QString session_id;
        QString user_name;
        QString user_password;
    } SECURITY_INFO;



    API_STATE CurState;
    SECURITY_INFO sec_info;

    bool is_login;
    QUrl login_url;
    QUrl logout_url;
    QUrl create_folder_url;
    QUrl upload_url;
    QUrl folder_list_url;
    QNetworkAccessManager *network_manager;
    QNetworkRequest req;
    QString req_params;

    QByteArray image_data;
    QByteArray bytes;
    QString req_str;
    QByteArray post_array;
    QNetworkProxy proxy;
signals:

    void OnFinish(bool result);
    void OnError(bool result);


};

#endif // SHOTSCREENSWEBAPI_H
